<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The MongoDB\Driver\Server class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongodb-driver-cursorid.unserialize.html">« MongoDB\Driver\CursorId::unserialize</a></li>
      <li style="float: right;"><a href="mongodb-driver-server.construct.html">MongoDB\Driver\Server::__construct »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.mongodb.html">MongoDB\Driver</a></li>
    <li>The MongoDB\Driver\Server class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.mongodb-driver-server" class="reference">

 <h1 class="title">The MongoDB\Driver\Server class</h1>
 

 <div class="partintro"><p class="verinfo">(mongodb &gt;=1.0.0)</p>


  <div class="section" id="mongodb-driver-server.intro">
   <h2 class="title">简介</h2>
   <p class="para">

   </p>
  </div>


  <div class="section" id="mongodb-driver-server.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="modifier">final</span>
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">MongoDB\Driver\Server</strong>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-server.html#mongodb-driver-server.constants.type-unknown"><var class="varname">TYPE_UNKNOWN</var></a></var><span class="initializer"> = 0</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-server.html#mongodb-driver-server.constants.type-standalone"><var class="varname">TYPE_STANDALONE</var></a></var><span class="initializer"> = 1</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-server.html#mongodb-driver-server.constants.type-mongos"><var class="varname">TYPE_MONGOS</var></a></var><span class="initializer"> = 2</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-server.html#mongodb-driver-server.constants.type-possible-primary"><var class="varname">TYPE_POSSIBLE_PRIMARY</var></a></var><span class="initializer"> = 3</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-server.html#mongodb-driver-server.constants.type-rs-primary"><var class="varname">TYPE_RS_PRIMARY</var></a></var><span class="initializer"> = 4</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-server.html#mongodb-driver-server.constants.type-rs-secondary"><var class="varname">TYPE_RS_SECONDARY</var></a></var><span class="initializer"> = 5</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-server.html#mongodb-driver-server.constants.type-rs-arbiter"><var class="varname">TYPE_RS_ARBITER</var></a></var><span class="initializer"> = 6</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-server.html#mongodb-driver-server.constants.type-rs-other"><var class="varname">TYPE_RS_OTHER</var></a></var><span class="initializer"> = 7</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-server.html#mongodb-driver-server.constants.type-rs-ghost"><var class="varname">TYPE_RS_GHOST</var></a></var><span class="initializer"> = 8</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-server.html#mongodb-driver-server.constants.type-load-balancer"><var class="varname">TYPE_LOAD_BALANCER</var></a></var><span class="initializer"> = 9</span>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">private</span> <span class="methodname"><a href="mongodb-driver-server.construct.html" class="methodname">__construct</a></span>()</div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.executebulkwrite.html" class="methodname">executeBulkWrite</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$namespace</code></span>, <span class="methodparam"><span class="type"><a href="class.mongodb-driver-bulkwrite.html" class="type MongoDB\Driver\BulkWrite">MongoDB\Driver\BulkWrite</a></span> <code class="parameter">$bulk</code></span>, <span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type"><a href="class.mongodb-driver-writeconcern.html" class="type MongoDB\Driver\WriteConcern">MongoDB\Driver\WriteConcern</a></span>|<span class="type">null</span></span> <code class="parameter">$options</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><a href="class.mongodb-driver-writeresult.html" class="type MongoDB\Driver\WriteResult">MongoDB\Driver\WriteResult</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.executecommand.html" class="methodname">executeCommand</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$db</code></span>, <span class="methodparam"><span class="type"><a href="class.mongodb-driver-command.html" class="type MongoDB\Driver\Command">MongoDB\Driver\Command</a></span> <code class="parameter">$command</code></span>, <span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type"><a href="class.mongodb-driver-readpreference.html" class="type MongoDB\Driver\ReadPreference">MongoDB\Driver\ReadPreference</a></span>|<span class="type">null</span></span> <code class="parameter">$options</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><a href="class.mongodb-driver-cursor.html" class="type MongoDB\Driver\Cursor">MongoDB\Driver\Cursor</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.executequery.html" class="methodname">executeQuery</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$namespace</code></span>, <span class="methodparam"><span class="type"><a href="class.mongodb-driver-query.html" class="type MongoDB\Driver\Query">MongoDB\Driver\Query</a></span> <code class="parameter">$query</code></span>, <span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type"><a href="class.mongodb-driver-readpreference.html" class="type MongoDB\Driver\ReadPreference">MongoDB\Driver\ReadPreference</a></span>|<span class="type">null</span></span> <code class="parameter">$options</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><a href="class.mongodb-driver-cursor.html" class="type MongoDB\Driver\Cursor">MongoDB\Driver\Cursor</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.executereadcommand.html" class="methodname">executeReadCommand</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$db</code></span>, <span class="methodparam"><span class="type"><a href="class.mongodb-driver-command.html" class="type MongoDB\Driver\Command">MongoDB\Driver\Command</a></span> <code class="parameter">$command</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">array</span><span class="type"></span></span> <code class="parameter">$options</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><a href="class.mongodb-driver-cursor.html" class="type MongoDB\Driver\Cursor">MongoDB\Driver\Cursor</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.executereadwritecommand.html" class="methodname">executeReadWriteCommand</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$db</code></span>, <span class="methodparam"><span class="type"><a href="class.mongodb-driver-command.html" class="type MongoDB\Driver\Command">MongoDB\Driver\Command</a></span> <code class="parameter">$command</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">array</span><span class="type"></span></span> <code class="parameter">$options</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><a href="class.mongodb-driver-cursor.html" class="type MongoDB\Driver\Cursor">MongoDB\Driver\Cursor</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.executewritecommand.html" class="methodname">executeWriteCommand</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$db</code></span>, <span class="methodparam"><span class="type"><a href="class.mongodb-driver-command.html" class="type MongoDB\Driver\Command">MongoDB\Driver\Command</a></span> <code class="parameter">$command</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">array</span><span class="type"></span></span> <code class="parameter">$options</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><a href="class.mongodb-driver-cursor.html" class="type MongoDB\Driver\Cursor">MongoDB\Driver\Cursor</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.gethost.html" class="methodname">getHost</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.getinfo.html" class="methodname">getInfo</a></span>(): <span class="type">array</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.getlatency.html" class="methodname">getLatency</a></span>(): <span class="type"><span class="type">?</span><span class="type">integer</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.getport.html" class="methodname">getPort</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.getserverdescription.html" class="methodname">getServerDescription</a></span>(): <span class="type"><span class="type MongoDB\Driver\ServerDescription">MongoDB\Driver\ServerDescription</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.gettags.html" class="methodname">getTags</a></span>(): <span class="type">array</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.gettype.html" class="methodname">getType</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.isarbiter.html" class="methodname">isArbiter</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.ishidden.html" class="methodname">isHidden</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.ispassive.html" class="methodname">isPassive</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.isprimary.html" class="methodname">isPrimary</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-server.issecondary.html" class="methodname">isSecondary</a></span>(): <span class="type">bool</span></div>

   }</div>


  </div>
  

  <div class="section" id="mongodb-driver-server.constants">
   <h2 class="title">预定义常量</h2>
   <dl>

    
     <dt id="mongodb-driver-server.constants.type-unknown"><strong><code>MongoDB\Driver\Server::TYPE_UNKNOWN</code></strong></dt>

     <dd>

      <p class="para">Unknown server type, returned by <span class="methodname"><a href="mongodb-driver-server.gettype.html" class="methodname">MongoDB\Driver\Server::getType()</a></span>.</p>
     </dd>

    

    
     <dt id="mongodb-driver-server.constants.type-standalone"><strong><code>MongoDB\Driver\Server::TYPE_STANDALONE</code></strong></dt>

     <dd>

      <p class="para">Standalone server type, returned by <span class="methodname"><a href="mongodb-driver-server.gettype.html" class="methodname">MongoDB\Driver\Server::getType()</a></span>.</p>
     </dd>

    

    
     <dt id="mongodb-driver-server.constants.type-mongos"><strong><code>MongoDB\Driver\Server::TYPE_MONGOS</code></strong></dt>

     <dd>

      <p class="para">Mongos server type, returned by <span class="methodname"><a href="mongodb-driver-server.gettype.html" class="methodname">MongoDB\Driver\Server::getType()</a></span>.</p>
     </dd>

    

    
     <dt id="mongodb-driver-server.constants.type-possible-primary"><strong><code>MongoDB\Driver\Server::TYPE_POSSIBLE_PRIMARY</code></strong></dt>

     <dd>

      <p class="para">Replica set possible primary server type, returned by <span class="methodname"><a href="mongodb-driver-server.gettype.html" class="methodname">MongoDB\Driver\Server::getType()</a></span>.</p>
      <p class="para">A server may be identified as a possible primary if it has not yet been checked but another memory of the replica set thinks it is the primary.</p>
     </dd>

    

    
     <dt id="mongodb-driver-server.constants.type-rs-primary"><strong><code>MongoDB\Driver\Server::TYPE_RS_PRIMARY</code></strong></dt>

     <dd>

      <p class="para">Replica set primary server type, returned by <span class="methodname"><a href="mongodb-driver-server.gettype.html" class="methodname">MongoDB\Driver\Server::getType()</a></span>.</p>
     </dd>

    

    
     <dt id="mongodb-driver-server.constants.type-rs-secondary"><strong><code>MongoDB\Driver\Server::TYPE_RS_SECONDARY</code></strong></dt>

     <dd>

      <p class="para">Replica set secondary server type, returned by <span class="methodname"><a href="mongodb-driver-server.gettype.html" class="methodname">MongoDB\Driver\Server::getType()</a></span>.</p>
     </dd>

    

    
     <dt id="mongodb-driver-server.constants.type-rs-arbiter"><strong><code>MongoDB\Driver\Server::TYPE_RS_ARBITER</code></strong></dt>

     <dd>

      <p class="para">Replica set arbiter server type, returned by <span class="methodname"><a href="mongodb-driver-server.gettype.html" class="methodname">MongoDB\Driver\Server::getType()</a></span>.</p>
     </dd>

    

    
     <dt id="mongodb-driver-server.constants.type-rs-other"><strong><code>MongoDB\Driver\Server::TYPE_RS_OTHER</code></strong></dt>

     <dd>

      <p class="para">Replica set other server type, returned by <span class="methodname"><a href="mongodb-driver-server.gettype.html" class="methodname">MongoDB\Driver\Server::getType()</a></span>.</p>
      <p class="para">Such servers may be hidden, starting up, or recovering. They cannot be queried, but their hosts lists are useful for discovering the current replica set configuration.</p>
     </dd>

    

    
     <dt id="mongodb-driver-server.constants.type-rs-ghost"><strong><code>MongoDB\Driver\Server::TYPE_RS_GHOST</code></strong></dt>

     <dd>

      <p class="para">Replica set ghost server type, returned by <span class="methodname"><a href="mongodb-driver-server.gettype.html" class="methodname">MongoDB\Driver\Server::getType()</a></span>.</p>
      <p class="para">Servers may be identified as such in at least three situations: briefly during server startup; in an uninitialized replica set; or when the server is shunned (i.e. removed from the replica set config). They cannot be queried, nor can their host list be used to discover the current replica set configuration; however, the client may monitor this server in hope that it transitions to a more useful state.</p>
     </dd>

    

    
     <dt id="mongodb-driver-server.constants.type-load-balancer"><strong><code>MongoDB\Driver\Server::TYPE_LOAD_BALANCER</code></strong></dt>

     <dd>

      <p class="para">Load balancer server type, returned by <span class="methodname"><a href="mongodb-driver-server.gettype.html" class="methodname">MongoDB\Driver\Server::getType()</a></span>.</p>
     </dd>

    

   </dl>

  </div>


  <div class="section">
   <h2 class="title">更新日志</h2>
   <p class="para">
    <table class="doctable informaltable">
     
      <thead>
       <tr>
        <th>版本</th>
        <th>说明</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td>PECL mongodb 1.11.0</td>
        <td>
         <p class="para">
          Added the
          <strong><code>MongoDB\Driver\Server::TYPE_LOAD_BALANCER</code></strong>
          constant.
         </p>
        </td>
       </tr>

      </tbody>
     
    </table>

   </p>
  </div>

 </div>

 
 
















































 




















 






 






 






 






 






 






 






 






 







<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="mongodb-driver-server.construct.html">MongoDB\Driver\Server::__construct</a> — Create a new Server (not used)</li><li><a href="mongodb-driver-server.executebulkwrite.html">MongoDB\Driver\Server::executeBulkWrite</a> — Execute one or more write operations on this server</li><li><a href="mongodb-driver-server.executecommand.html">MongoDB\Driver\Server::executeCommand</a> — Execute a database command on this server</li><li><a href="mongodb-driver-server.executequery.html">MongoDB\Driver\Server::executeQuery</a> — Execute a database query on this server</li><li><a href="mongodb-driver-server.executereadcommand.html">MongoDB\Driver\Server::executeReadCommand</a> — Execute a database command that reads on this server</li><li><a href="mongodb-driver-server.executereadwritecommand.html">MongoDB\Driver\Server::executeReadWriteCommand</a> — Execute a database command that reads and writes on this server</li><li><a href="mongodb-driver-server.executewritecommand.html">MongoDB\Driver\Server::executeWriteCommand</a> — Execute a database command that writes on this server</li><li><a href="mongodb-driver-server.gethost.html">MongoDB\Driver\Server::getHost</a> — Returns the hostname of this server</li><li><a href="mongodb-driver-server.getinfo.html">MongoDB\Driver\Server::getInfo</a> — Returns an array of information describing this server</li><li><a href="mongodb-driver-server.getlatency.html">MongoDB\Driver\Server::getLatency</a> — Returns the latency of this server in milliseconds</li><li><a href="mongodb-driver-server.getport.html">MongoDB\Driver\Server::getPort</a> — Returns the port on which this server is listening</li><li><a href="mongodb-driver-server.getserverdescription.html">MongoDB\Driver\Server::getServerDescription</a> — Returns a ServerDescription for this server</li><li><a href="mongodb-driver-server.gettags.html">MongoDB\Driver\Server::getTags</a> — Returns an array of tags describing this server in a replica set</li><li><a href="mongodb-driver-server.gettype.html">MongoDB\Driver\Server::getType</a> — Returns an integer denoting the type of this server</li><li><a href="mongodb-driver-server.isarbiter.html">MongoDB\Driver\Server::isArbiter</a> — Checks if this server is an arbiter member of a replica set</li><li><a href="mongodb-driver-server.ishidden.html">MongoDB\Driver\Server::isHidden</a> — Checks if this server is a hidden member of a replica set</li><li><a href="mongodb-driver-server.ispassive.html">MongoDB\Driver\Server::isPassive</a> — Checks if this server is a passive member of a replica set</li><li><a href="mongodb-driver-server.isprimary.html">MongoDB\Driver\Server::isPrimary</a> — Checks if this server is a primary member of a replica set</li><li><a href="mongodb-driver-server.issecondary.html">MongoDB\Driver\Server::isSecondary</a> — Checks if this server is a secondary member of a replica set</li></ul>
</div>
</div></div></body></html>